package com.hc.sort.server.view;

import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.event.*;

public class ServerUI extends JFrame {
	Server server;

	private JPanel contentPane;
	JTextPane textPaneTake;
	JTextPane textPaneCall;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ServerUI frame = new ServerUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ServerUI() {
		setTitle("服务端");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 845, 540);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel takeTitle = new JLabel("取号端的请求");
		takeTitle.setFont(new Font("宋体", Font.PLAIN, 18));
		takeTitle.setBounds(43, 23, 131, 33);
		contentPane.add(takeTitle);
		
		JLabel callTitle = new JLabel("叫号端的请求");
		callTitle.setFont(new Font("宋体", Font.PLAIN, 18));
		callTitle.setBounds(470, 23, 131, 33);
		contentPane.add(callTitle);
		
		JButton serverBtn = new JButton("启动服务");
		serverBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				if ("启动服务".equals(serverBtn.getText())) {
					//启动服务
					serverBtn.setText("关闭服务");
					
					server=new Server(ServerUI.this);
					Thread t=new Thread(server);
					t.start();
				}else {
					//关闭服务
					serverBtn.setText("启动服务");
					server.stopServer();
				}
			}
		});
		serverBtn.setFont(new Font("宋体", Font.PLAIN, 18));
		serverBtn.setBounds(263, 421, 337, 43);
		contentPane.add(serverBtn);
		
		textPaneTake = new JTextPane();
		textPaneTake.setBounds(43, 58, 316, 320);
		contentPane.add(textPaneTake);
		
		textPaneCall = new JTextPane();
		textPaneCall.setBounds(470, 58, 316, 320);
		contentPane.add(textPaneCall);
	}
	
	public void  writeLog(String msg) {
		String content=textPaneTake.getText()+"\r\n"+msg;
		textPaneTake.setText(content);
	}
}
